package logic

import (
	"api/pkg"
	"context"
	"user_srv/user"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RealNameLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRealNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealNameLogic {
	return &RealNameLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RealNameLogic) RealName(req *types.RealNameRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	name, err := l.svcCtx.UserSrv.RealName(l.ctx, &user.RealNameRequest{
		UserId:   req.UserId,
		RealName: req.RealName,
		IdCord:   req.IdCord,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: pkg.Tri(err.Error()),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "实名认证成功",
		Data: map[string]interface{}{
			"RealName": name,
		},
	}, nil
}
